import {
  getUserApi,
  getProfileEditApi,
  updatePhotoAPI,
  updateProfileAPI,
} from '@/api/user';
import { AppDispatch } from '..';
import { ProFileType } from '../reducers/user';

// 发送验证码
export const getUserAction = () => {
  return async (dispatch: AppDispatch) => {
    const res = await getUserApi();
    // console.log(res);
    dispatch({ type: 'user/saveUserInfo', payload: res.data });
  };
};
// 个人资料
export const ProfileEditAction = () => {
  return async (dispatch: AppDispatch) => {
    const res = await getProfileEditApi();
    // console.log(res);
    dispatch({ type: 'user/saveProfileInfo', payload: res.data });
  };
};

// 上传图片
export const updatePhotoAction = (data: FormData) => {
  return async (dispatch: AppDispatch) => {
    const res = await updatePhotoAPI(data);
    // console.log(res);
    dispatch({ type: 'user/uploadProfile', payload: res.data });
  };
};
// 修改性别
export const updatePeofileAction = (data: Partial<ProFileType>) => {
  return async (dispatch: AppDispatch) => {
    const res = await updateProfileAPI(data);
    console.log(res);
    dispatch({ type: 'user/updateProfile', payload: data });
  };
};
